package net.bsayiner.LcdTester;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

public class LCDTesterActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	public void onBtnStartTestClick(View view) {
		Intent intent = new Intent(this, ScreenTestActivity.class);
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_activity_menu_structure, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_about:
			PackageInfo packageInfo = null;
			try {
				packageInfo = getPackageManager().getPackageInfo("net.bsayiner.LcdTester", 0);
			} catch (NameNotFoundException e) {
				e.printStackTrace();
			}
			final AlertDialog.Builder alert = new AlertDialog.Builder(this);
			alert.setTitle("LCD Tester v" + packageInfo.versionName);
			alert.setMessage("Copyright (C) 2011 Bora SAYINER\nEmail : bsayiner@bsayiner.net");
			alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			});
			alert.show();
			return true;
		case R.id.menu_exit:
			System.exit(0);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}